package com.kfm.base.net;

import java.io.IOException;
import java.io.InputStream;
import java.io.OutputStream;
import java.net.*;

public class ChatTest {

    public static void main(String[] args) {

        try (Socket socket = new Socket(InetAddress.getLocalHost(), 8888);){
            OutputStream outputStream = socket.getOutputStream();

            outputStream.write("hello everyone".getBytes());

            socket.shutdownOutput();

            InputStream inputStream = socket.getInputStream();

            byte[] bytes = inputStream.readAllBytes();

            System.out.println(new String(bytes));

        } catch (IOException e) {
            throw new RuntimeException(e);
        }
    }
}
